// 2025/10/18
// 删除排序链表中的重复元素

/**
 * Definition for singly-linked list.
 * struct ListNode {
 *     int val;
 *     ListNode *next;
 *     ListNode() : val(0), next(nullptr) {}
 *     ListNode(int x) : val(x), next(nullptr) {}
 *     ListNode(int x, ListNode *next) : val(x), next(next) {}
 * };
 */
class Solution {
public:
    ListNode* deleteDuplicates(ListNode* head) {
        ListNode ans(101, head), *prev = &ans, *cur = head;
        while(cur && cur->next)
        {
            if(cur->val == cur->next->val)
            {
                while(cur && cur->next && cur->val == cur->next->val)
                {
                    cur = cur->next;
                }
                cur = cur->next;
                prev->next = cur;
            }
            else
            {
                prev = cur;
                cur = cur->next;
            }
        }
        return ans.next;
    }
};